package com.polidea.rxohosble2.sample.util;

import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentState;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.components.element.StateElement;
import ohos.agp.utils.Color;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

public class Utils {
    public static void showToast(Context context, String text) {
        new ToastDialog(context).setContentText(text).setDuration(200).show();
    }

    public static Element getColorElement(int color) {
        ShapeElement bgColorElement = new ShapeElement();
        bgColorElement.setRgbColor(RgbColor.fromArgbInt(color));
        return bgColorElement;
    }

    public static void setBackground(Component component) {
        StateElement element = new StateElement();
        element.addState(new int[]{ComponentState.COMPONENT_STATE_DISABLED}, getColorElement(Color.GRAY.getValue()));
        element.addState(new int[]{ComponentState.COMPONENT_STATE_PRESSED}, getColorElement(Color.RED.getValue()));
        element.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, getColorElement(Color.YELLOW.getValue()));
        component.setBackground(element);
    }
}
